package com.imis.module.api.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.imis.base.globle.Result;
import com.imis.module.api.bus.SysLoginBus;
import com.imis.module.api.model.ro.SysLoginRO;
import com.imis.module.api.model.ro.SysPhoneLoginRO;
import com.imis.module.api.model.ro.SysRegisterRO;
import com.imis.module.api.model.ro.SysUserPasswordChangeRO;
import com.imis.module.base.BaseController;
import com.imis.module.system.model.vo.SysMenuTreeVO;
import com.imis.module.system.model.vo.SysUserVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * LoginController<br>
 * 用户登录模块
 * </p>
 *
 * @author XinLau
 * @version 1.0
 * @since 2020年04月15日 11:54
 */
@Slf4j
@RestController
@RequestMapping("/sys")
@Api(tags = {"登录模块"})
@ApiSort(1)
public class LoginController extends BaseController<SysLoginBus> {

    @RequestMapping(value = "/register", method = RequestMethod.POST)
    @ApiOperation(value = "用户注册接口", notes = "注册")
    @ApiOperationSupport(order = 1, author = "XinLau")
    public Result register(@RequestBody @Valid SysRegisterRO sysRegister) {
        return service.register(sysRegister);
    }

    @RequestMapping(value = "/login", method = RequestMethod.POST)
    @ApiOperation(value = "用户登录接口", notes = "登录")
    @ApiOperationSupport(order = 2, author = "XinLau")
    public Result<SysUserVO> login(@RequestBody @Valid SysLoginRO sysLogin) {
        return service.login(sysLogin);
    }

    @RequestMapping(value = "/phoneLogin", method = RequestMethod.POST)
    @ApiOperation(value = "手机登录接口", notes = "登录")
    @ApiOperationSupport(order = 3, author = "XinLau")
    public Result<SysUserVO> loginByPhone(@RequestBody @Valid SysPhoneLoginRO sysPhoneLogin) {
        return service.loginByPhone(sysPhoneLogin);
    }

    @RequestMapping(value = "/passwordChange", method = RequestMethod.PUT)
    @ApiOperation(value = "修改密码接口", notes = "用户自助修改密码")
    @ApiOperationSupport(order = 4, author = "XinLau")
    public Result passwordChange(@RequestBody @Valid SysUserPasswordChangeRO sysUserPasswordChange) {
        return service.passwordChange(sysUserPasswordChange);
    }

    @RequestMapping(value = "/logout", method = RequestMethod.POST)
    @ApiOperation(value = "用户注销接口", notes = "注销")
    @ApiOperationSupport(order = 5, author = "XinLau")
    public Result logout(HttpServletRequest request) {
        return service.logout(request);
    }

    @RequestMapping(value = "/querySysMenuTreeListByCurrentUser", method = RequestMethod.GET)
    @ApiOperation(value = "获取功能菜单", notes = "菜单树")
    @ApiOperationSupport(order = 6, author = "XinLau")
    public Result<List<SysMenuTreeVO>> querySysMenuTreeListByCurrentUser() {
        return service.querySysMenuTreeListByCurrentUser();
    }

}
